package cn.wing.key;

import cn.wing.event.OpenSharedMenuPacket;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import static cn.wing.PlayTradingMain.CHANNEL;
import static cn.wing.PlayTradingMain.MOD_ID;

@Mod.EventBusSubscriber(modid = MOD_ID, value = Dist.CLIENT)
public class KeyHandler {

    @SubscribeEvent
    public static void onClientTick(TickEvent.ClientTickEvent e) {
        if (e.phase != TickEvent.Phase.END) return;
        while (KeyInit.OPEN_GUI_KEY.consumeClick()) {
            if (Minecraft.getInstance().screen == null) {
                CHANNEL.sendToServer(new OpenSharedMenuPacket());
            } else {
                Minecraft.getInstance().setScreen(null);
            }
        }
    }
}
